<template>
  <div v-loading="loading" class="dialog">
    <div class="title">资源修改/新增</div>
    <el-dialog :title="addShow == 1 ? '新增' : '修改'" :visible.sync="addShow" width="70%" append-to-body>
      <div style="max-height: 90vh; overflow-y: scroll">
        <AddBdialog
          ref="addBdialog"
          :configure="configure"
          :hosts="form.hosts"
          :supplierCode="supplierCode"
          @addTable="addTable"
        />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="$refs.addBdialog.submit()">确 定</el-button>
        <el-button @click="addShow = false">取 消</el-button>
      </div>
    </el-dialog>
    <!--  <el-button
            type="primary"
            style="padding: 10px 40px"
            @click="showAdd(1, false)"
            >新增</el-button
        > -->
    <div class="wrap">
      <div class="wrap_title">
        <div>服务器</div>
      </div>
      <div style="padding: 20px 20px; width: 100%">
        <el-input style="width: 200px" size="mini" placeholder="可输入实例名称搜索" v-model="specifyIp" clearable />
        <el-table :data="filterBySpecifyIp" style="width: 100%; margin-top: 13px">
          <el-table-column label="资源类型">
            <template slot-scope="scope">
              {{
                scope.row.flavorType == 1
                  ? "云服务器"
                  : scope.row.flavorType == 2
                  ? "高性能服务器"
                  : scope.row.serverCode
                  ? "数据库"
                  : "存储产品"
              }}
            </template>
          </el-table-column>
          <el-table-column label="实例名称">
            <template slot-scope="scope">
              <span v-if="scope.row.flavorType">{{ scope.row.specifyIp || "" }}</span>
              <span v-else-if="scope.row.serverCode">{{ scope.row.hostInstanceName }}</span>
              <span v-else-if="!scope.row.hostInstanceNames.length"></span>
              <div v-else style="margin-bottom: 6px" v-for="(item, index) in scope.row.hostInstanceNames" :key="index">
                {{ item }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="资源详情">
            <template slot-scope="scope">
              <div
                v-if="oldform.hosts[scope.row.formIndex].flavorType"
                placement="top-start"
                width="300"
                trigger="hover"
              >
                <div style="margin-bottom: 6px">
                  <label>可用域：</label>{{ oldform.hosts[scope.row.formIndex].availableDomain_label }}
                </div>
                <div style="margin-bottom: 6px" v-if="oldform.hosts[scope.row.formIndex].flavorType != 1">
                  <label>资源类型：</label>
                  {{ oldform.hosts[scope.row.formIndex].cloudFlavorCode_label }}
                </div>
                <div style="margin-bottom: 6px" v-if="oldform.hosts[scope.row.formIndex].flavorType == 1">
                  <label>规格：</label>
                  {{ oldform.hosts[scope.row.formIndex].cpuNumber }}核vCPU；{{
                    oldform.hosts[scope.row.formIndex].memorySize
                  }}G内存；
                </div>
                <div style="margin-bottom: 6px" v-if="oldform.hosts[scope.row.formIndex].flavorType == 2">
                  <label>规格：</label>{{ oldform.hosts[scope.row.formIndex].cloudFlavorCode_desc }}
                </div>
                <div
                  style="margin-bottom: 6px"
                  v-if="oldform.hosts[scope.row.formIndex].flavorType == 1 && oldform.hosts[scope.row.formIndex].osDisk"
                >
                  <label>系统盘：</label
                  >{{
                    oldform.hosts[scope.row.formIndex].osDisk
                      ? oldform.hosts[scope.row.formIndex].osDisk.diskServerCode_label
                      : ""
                  }}，{{
                    oldform.hosts[scope.row.formIndex].osDisk
                      ? oldform.hosts[scope.row.formIndex].osDisk.dataDiskSize
                      : ""
                  }}GB
                </div>
                <div style="margin-bottom: 6px">
                  <label>操作系统：</label>
                  <!-- {{ oldform.hosts[scope.row.formIndex].osName }} -->
                  {{
                    oldform.hosts[scope.row.formIndex].osName || osName(oldform.hosts[scope.row.formIndex].osServerCode)
                  }}
                </div>
                <div
                  style="margin-bottom: 6px"
                  v-if="oldform.hosts[scope.row.formIndex].flavorType == 1 && oldform.hosts[scope.row.formIndex].disks"
                >
                  <label>
                    数据盘(共<span style="color: #e83112">{{ oldform.hosts[scope.row.formIndex].disks.length }}</span
                    >块){{ oldform.hosts[scope.row.formIndex].disks.length ? ":" : "" }}</label
                  >
                </div>
                <div
                  style="margin: 0 0 6px 16px"
                  v-for="(item, index) in oldform.hosts[scope.row.formIndex].disks"
                  :key="index"
                  v-if="oldform.hosts[scope.row.formIndex].flavorType == 1 && oldform.hosts[scope.row.formIndex].disks"
                >
                  <span>{{ item.diskServerCode_label || item.diskServerName }}</span
                  >，{{ item.dataDiskSize }}GB
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="变更后">
            <template slot-scope="scope">
              <div v-show="!scope.row.insStatus">未变更</div>
              <div v-show="(scope.row.insStatus ? scope.row.insStatus : '') == 'REMOVE'">已删除</div>
              <div v-show="scope.row.insStatus == 'UPDATE'">
                <div v-if="scope.row.flavorType" placement="top-start" width="300" trigger="hover">
                  <div style="margin-bottom: 6px"><label>可用域：</label>{{ scope.row.availableDomain_label }}</div>
                  <div style="margin-bottom: 6px" v-if="scope.row.flavorType != 1">
                    <label>资源类型：</label>
                    {{ scope.row.cloudFlavorCode_label }}
                  </div>
                  <div style="margin-bottom: 6px" v-if="scope.row.flavorType == 1">
                    <label>规格：</label>
                    {{ scope.row.cpuNumber }}vCPU； {{ scope.row.memorySize }}G内存
                  </div>
                  <div style="margin-bottom: 6px" v-if="scope.row.flavorType == 2">
                    <label>规格：</label>
                    {{ scope.row.cloudFlavorCode_desc }}
                  </div>
                  <div style="margin-bottom: 6px" v-if="scope.row.flavorType == 1 && scope.row.osDisk">
                    <label>系统盘：</label>{{ scope.row.osDisk ? scope.row.osDisk.diskServerCode_label : "" }}，{{
                      scope.row.osDisk ? scope.row.osDisk.dataDiskSize : ""
                    }}GB
                  </div>
                  <div style="margin-bottom: 6px">
                    <label>操作系统：</label>
                    <!-- {{ scope.row.osName }} -->
                    {{ scope.row.osName || osName(scope.row.osServerCode) }}
                  </div>
                  <template v-if="scope.row.flavorType == 1 && scope.row.disks">
                    <div style="margin-bottom: 6px">
                      <label>
                        数据盘(共<span style="color: #e83112">{{ scope.row.disks.length }}</span
                        >块){{ scope.row.disks.length ? ":" : "" }}</label
                      >
                    </div>
                    <div style="margin: 0 0 6px 16px" v-for="(item, index) in scope.row.disks" :key="index">
                      <span>{{ item.diskServerCode_label }}</span
                      >，{{ item.dataDiskSize }}GB
                    </div>
                  </template>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit-outline"
                v-show="scope.row.insStatus != 'REMOVE'"
                @click="showAdd(2, scope.row, scope.row.formIndex)"
                >修改
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                v-show="scope.row.insStatus != 'REMOVE'"
                @click="del(scope.row, scope.row.formIndex, 1)"
                >删除
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-refresh-left"
                v-show="scope.row.insStatus != 'ADD'"
                @click="huanyuan(scope.row, scope.row.formIndex, 1)"
                >还原
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="wrap">
      <div class="wrap_title">
        <div>数据库</div>
      </div>
      <div style="padding: 20px 20px; width: 100%">
        <el-table :data="form.databases" style="width: 100%; margin-top: 13px">
          <el-table-column label="版本">
            <template slot-scope="scope">
              <span>{{ scope.row.serverName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="资源详情">
            <template slot-scope="scope">
              <div placement="top-start" width="300" trigger="hover">
                <div style="margin-bottom: 6px">
                  <label>类型：</label>{{ oldform.databases[scope.$index].serverCode_label }}
                </div>
                <!-- <div style="margin-bottom: 6px">
                                    <label>版本：</label
                                    >{{ oldform.databases[scope.$index].databaseVersion }}
                                </div> -->
                <div style="margin-bottom: 6px">
                  <label>位数：</label>{{ oldform.databases[scope.$index].systemDigits }}
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="变更后">
            <template slot-scope="scope">
              <div v-show="!scope.row.insStatus">未变更</div>
              <div v-show="(scope.row.insStatus ? scope.row.insStatus : '') == 'REMOVE'">已删除</div>
              <div v-show="form.databases[scope.$index].insStatus == 'UPDATE'">
                <div placement="top-start" width="300" trigger="hover">
                  <div style="margin-bottom: 6px">
                    <label>类型：</label>{{ scope.row.serverName || scope.row.serverCode }}
                  </div>
                  <!-- <div style="margin-bottom: 6px">
                                    <label>版本：</label
                                    >{{ scope.row.databaseVersion }}
                                </div> -->
                  <div style="margin-bottom: 6px"><label>位数：</label>{{ scope.row.systemDigits }}</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit-outline"
                v-show="scope.row.insStatus != 'REMOVE'"
                @click="showAdd(2, scope.row, scope.$index)"
                >修改
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                v-show="scope.row.insStatus != 'REMOVE'"
                @click="del(scope.row, scope.$index, 2)"
                >删除
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-refresh-left"
                v-show="scope.row.insStatus != 'ADD'"
                @click="huanyuan(scope.row, scope.$index, 2)"
                >还原
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="wrap">
      <div class="wrap_title">
        <div>存储产品</div>
      </div>
      <div style="padding: 20px 20px; width: 100%">
        <el-table :data="form.storeProducts" style="width: 100%; margin-top: 13px">
          <el-table-column label="磁盘类型">
            <template slot-scope="scope">
              <!-- {{ scope.row.diskServerCode_label }} -->
              {{ oldform.storeProducts[scope.$index].diskServerName }}
            </template>
          </el-table-column>
          <el-table-column label="磁盘用量">
            <template slot-scope="scope">
              <!-- <span> {{ scope.row.dataDiskSize }}GB </span> -->
              {{ oldform.storeProducts[scope.$index].dataDiskSize }}GB
            </template>
          </el-table-column>
          <el-table-column label="资源详情">
            <template slot-scope="scope">
              <div placement="top-start" width="300" trigger="hover">
                <div style="margin-bottom: 6px">
                  <label>存储类型：</label>{{ oldform.storeProducts[scope.$index].productCode }}
                </div>
                <div style="margin-bottom: 6px">
                  <label>服务类型：</label>{{ oldform.storeProducts[scope.$index].diskCode }}
                </div>
                <div style="margin-bottom: 6px">
                  <label>磁盘类型：</label>{{ oldform.storeProducts[scope.$index].diskServerName }}
                </div>
                <div style="margin-bottom: 6px">
                  <label>磁盘用量：</label>{{ oldform.storeProducts[scope.$index].dataDiskSize }}GB
                </div>
                <div style="margin-bottom: 6px">
                  <label>服务器：</label>
                  <div v-for="(item, index) in oldform.storeProducts[scope.$index].hostIds" :key="index">
                    {{ gethostName(item) }}
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="变更后">
            <template slot-scope="scope">
              <div v-show="!scope.row.insStatus">未变更</div>
              <div v-show="(scope.row.insStatus ? scope.row.insStatus : '') == 'REMOVE'">已删除</div>
              <div v-show="form.storeProducts[scope.$index].insStatus == 'UPDATE'">
                <div placement="top-start" width="300" trigger="hover">
                  <div style="margin-bottom: 6px"><label>存储类型：</label>{{ scope.row.productCode }}</div>
                  <div style="margin-bottom: 6px"><label>服务类型：</label>{{ scope.row.diskCode }}</div>
                  <div style="margin-bottom: 6px">
                    <label>磁盘类型：</label>{{ scope.row.diskServerCode_label || scope.row.diskServerName }}
                  </div>
                  <div><label>磁盘用量：</label>{{ scope.row.dataDiskSize }}GB</div>
                  <div style="margin-bottom: 6px">
                    <label>服务器：</label>
                    <div v-for="(item, index) in scope.row.hostIds" :key="index">{{ gethostName(item) }}</div>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit-outline"
                v-show="scope.row.insStatus != 'REMOVE'"
                @click="showAdd(2, scope.row, scope.$index)"
                >修改
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                v-show="scope.row.insStatus != 'REMOVE'"
                @click="del(scope.row, scope.$index, 3)"
                >删除
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-refresh-left"
                v-show="scope.row.insStatus != 'ADD'"
                @click="huanyuan(scope.row, scope.$index, 3)"
                >还原
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="wrap">
      <div class="wrap_title">
        <div>安全产品</div>
      </div>
      <div style="padding: 20px 20px; width: 100%">
        <el-table :data="[].concat(form.safeProductsList)" style="width: 100%; margin-top: 13px">
          <el-table-column label="序号" width="60px">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="产品名称">
            <template slot-scope="scope">
              {{ scope.row.productName }}
            </template>
          </el-table-column>
          <el-table-column label="数量">
            <template slot-scope="scope">
              {{ scope.row.ysnum }}
            </template>
          </el-table-column>
          <el-table-column label="变更后数量">
            <template slot-scope="scope">
              {{ scope.row.num == scope.row.ysnum ? "未变更" : scope.row.num }}
            </template>
          </el-table-column>
          <el-table-column label="操作" class-name="small-padding fixed-width" v-if="form.confirmed == false">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit-outline" @click="editSafe(scope.$index)"
                >修改</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-checkbox-group style="margin-top: 20px" v-if="yyaqList && yyaqList.length" v-model="aqchecked">
          <el-checkbox v-for="(item, index) in yyaqList" :label="item.code" :key="item.code"
            >{{ item.serviceName }}
            <el-input
              type="number"
              size="mini"
              min="1"
              style="width: 100px; margin-bottom: 10px"
              placeholder="数量"
              v-model="aqcheckedCount[index]"
            />
          </el-checkbox>
        </el-checkbox-group>
        <!-- <el-table
                    :data="form.safeProducts"
                    style="width: 100%; margin-top: 13px"
                >
                    <el-table-column label="产品名称">
                        <template slot-scope="scope">
                            {{ scope.row.productName}}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="操作"
                        class-name="small-padding fixed-width"
                    >
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-delete"
                                v-show="scope.row.insStatus!='REMOVE'"
                                @click="del(scope.row, scope.$index,4)"
                                >删除
                              </el-button>
                              <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-refresh-left"
                                v-show="scope.row.insStatus!='ADD'"
                                @click="huanyuan(scope.row, scope.$index,4)"
                                >还原
                              </el-button>
                        </template>
                    </el-table-column>
                </el-table> -->
      </div>
    </div>
    <div class="wrap">
      <div class="wrap_title">
        <div>其他</div>
      </div>
      <div style="padding: 10px 20px">
        <div class="wrap_item" style="margin-top: 0">
          <div style="line-height: 28px">说明:</div>
          <div style="width: 500px">
            <el-input
              type="textarea"
              style="width: 100%"
              :autosize="{ minRows: 2, maxRows: 4 }"
              placeholder="请输入说明"
              v-model="form.remark"
            >
            </el-input>
          </div>
        </div>
        <file-list ref="fileList" :fileList="form.fileList" @changeFileList="changeFileList" />
      </div>
    </div>
  </div>
</template>

<script>
import AddBdialog from "./addBdialog.vue";
import { hosts } from "@/api/cloud/cloud";
import { uploadFile } from "@/api/system/upload.js";
import { getResourcesByCloudUpId } from "@/api/resources/change.js";
import { v4 as uuidv4 } from "uuid";
import fileList from "@/components/FileList/index.vue";
import { serviceByClazz } from "@/api/resources/apply";
export default {
  name: "addB",
  components: {
    AddBdialog,
    fileList,
  },
  props: {
    configure: {
      type: Object,
      default: {},
    },
    supplierCode: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      specifyIp: "",
      loading: false,
      addShow: false,
      index: 0,
      yyaqList: null,
      //旧数据
      oldform: null,
      fileListState: true,

      aqchecked: [],
      aqcheckedCount: [],
      // 数据
      form: {
        cloudSupplier: undefined, //服务商
        hosts: [], //服务器列表
        databases: [], //数据库列表
        storeProducts: [], //存储产品列表
        safeProducts: [], //安全产品真实数据
        remark: "", //说明
        fileList: [],
      },
      dialogImageUrl: "",
      dialogVisible: false,
      SelectedcloudServiceName: "",
      SelectedcloudService: "",
      cloudUpId: "",
      // 暂时上级传递的主机数据
      hosts: [],
      hostsIndex: 0,
    };
  },
  computed: {
    filterBySpecifyIp() {
      let list = [];
      this.form.hosts.forEach((item, index) => {
        if (!this.specifyIp || (item.specifyIp && item.specifyIp.indexOf(this.specifyIp) > -1)) {
          item.formIndex = index;
          list.push(item);
        }
      });
      return list;
    },
  },
  created() {},
  methods: {
    changeFileList(fileList) {
      this.$set(this.form, "fileList", fileList);
    },
    gethostName(id) {
      let name = "";
      this.form.hosts.some((item) => {
        if (item.id == id) {
          name = item.hostName;
          return true;
        }
      });
      return name;
    },
    editSafe(index) {
      this.$prompt("请输入数量0~100", "", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        inputValue: this.form.safeProductsList[index].num,
      }).then((resp) => {
        if (!isNaN(resp.value) && parseInt(resp.value) >= 0 && parseInt(resp.value) <= 100) {
          console.log(resp.value, "xxx");
          this.form.safeProductsList[index].num = parseInt(resp.value);
          // this.NotModifyState=true
        }
      });
    },
    osName(code) {
      let serviceName;
      this.configure.czxtList.forEach((item) => {
        if (item.code == code) {
          serviceName = item.serviceName;
        }
      });
      return serviceName;
    },
    init(data) {
      if (this.oldform && this.oldform.id == data.id) {
        return;
      }
      data.safeProductsList = [];
      let aqchecked = [];
      for (let key in data.safeProducts) {
        data.safeProductsList.push({
          productName: key,
          num: data.safeProducts[key].length,
          ysnum: data.safeProducts[key].length,
        });
        aqchecked.push(data.safeProducts[key][0].productCode);
      }
      // detail.safeProducts.forEach(data=>{
      //       aqchecked.push(data.productCode)
      // })
      let detail = data;
      // detail.storeProducts.forEach((data) => {
      //     this.configure[
      //         data.productCode == "共享型" ? "ccList" : "fwcpList"
      //     ].some((it) => {
      //         if (it.code == data.diskServerCode) {
      //             data.diskServerCode_label = it.serviceName;
      //             return true;
      //         }
      //     });
      //     data.hostInstanceNames = [];
      //     if (data.hosts) {
      //         data.hostIds=[]
      //         data.hosts.forEach((item) => {
      //             data.hostIds.push(item.id)
      //             data.hostInstanceNames.push(item.instanceName);
      //         });
      //     }
      // });
      detail.databases.forEach((data, index) => {
        this.configure.sjkList.some((it) => {
          if (it.code == data.serverCode) {
            detail.databases[index].serverCode_label = it.serviceName;
            return true;
          }
        });
      });
      detail.hosts.forEach((data) => {
        data.hostName = data.instanceName;
        //可用域
        this.configure.available_domain.some((item) => {
          if (item.dictValue == data.availableDomain) {
            data.availableDomain_label = item.dictLabel;
            return true;
          }
        });
        //系统盘类型
        if (data.osDisk) {
          this.configure.storage_type.some((item) => {
            if (item.code == data.osDisk.diskServerCode) {
              data.osDisk.diskServerCode_label = item.serviceName;
              return true;
            }
          });
        }
        //数据盘类型
        if (data.disks) {
          data.disks.forEach((item) => {
            this.configure.ccList.some((it) => {
              if (it.code == item.diskServerCode) {
                item.diskServerCode_label = it.serviceName;
                return true;
              }
            });
          });
        } else {
          data.disks = [];
        }
        //规格
        if (data.flavorType == 1) {
          this.configure.codeList.some((item) => {
            if (item.specCode == data.cloudFlavorCode) {
              data.cloudFlavorCode_label = item.specName;
              data.cloudFlavorCode_desc = item.desc;
              return true;
            }
          });
        }
        if (data.flavorType == 2) {
          this.configure.wlfwqList.some((item) => {
            if (item.code == data.cloudFlavorCode) {
              data.cloudFlavorCode_label = item.serviceName;
              data.cloudFlavorCode_desc = item.remark;
              return true;
            }
          });
        }
      });

      detail.aqchecked = aqchecked;
      this.form = JSON.parse(JSON.stringify(detail));
      this.oldform = JSON.parse(JSON.stringify(detail));
      //安全产品列表
      serviceByClazz({ code: "yyaq", supplier: this.form.supplierCode }).then((response) => {
        this.yyaqList = response.data.filter((item) => {
          let flag = false;
          this.form.storeProducts.some((it) => {
            if (it.productName == item.productName) {
              flag = true;
              return true;
            }
          });
          return flag;
        });
      });
      for (let i = 0; i < 100; i++) {
        this.aqcheckedCount.push(1);
      }
    },
    // init2(n) {
    //   getResourcesByCloudUpId(n.id).then(res=>{
    //         let detail = res.data;
    //         detail.storeProducts.forEach((data) => {
    //             this.configure[
    //                 data.productCode == "共享型" ? "ccList" : "fwcpList"
    //             ].some((it) => {
    //                 if (it.code == data.diskServerCode) {
    //                     data.diskServerCode_label = it.serviceName;
    //                     return true;
    //                 }
    //             });
    //             data.hostInstanceNames = [];
    //             if (data.hosts) {
    //                 data.hostIds=[]
    //                 data.hosts.forEach((item) => {
    //                     data.hostIds.push(item.id)
    //                     data.hostInstanceNames.push(item.instanceName);
    //                 });
    //             }
    //         });
    //         detail.databases.forEach((data) => {
    //             this.configure.sjkList.some((it) => {
    //                 if (it.code == data.serverCode) {
    //                     data.serverCode_label = it.serviceName;
    //                     return true;
    //                 }
    //             });
    //         });
    //         detail.hosts.forEach((data) => {
    //             data.hostName = data.instanceName;
    //             //可用域
    //             this.configure.available_domain.some((item) => {
    //                 if (item.dictValue == data.availableDomain) {
    //                     data.availableDomain_label = item.dictLabel;
    //                     return true;
    //                 }
    //             });
    //             //系统盘类型
    //             if (data.osDisk) {
    //                 this.configure.storage_type.some((item) => {
    //                     if (item.code == data.osDisk.diskServerCode) {
    //                         data.osDisk.diskServerCode_label =
    //                             item.serviceName;
    //                         return true;
    //                     }
    //                 });
    //             }
    //             //数据盘类型
    //             if (data.disks) {
    //                 data.disks.forEach((item) => {
    //                     this.configure.ccList.some((it) => {
    //                         if (it.code == item.diskServerCode) {
    //                             item.diskServerCode_label = it.serviceName;
    //                             return true;
    //                         }
    //                     });
    //                 });
    //             } else {
    //                 data.disks = [];
    //             }
    //             //规格
    //             if (data.flavorType == 1) {
    //                 this.configure.codeList.some((item) => {
    //                     if (item.specCode == data.cloudFlavorCode) {
    //                         data.cloudFlavorCode_label = item.specName;
    //                         data.cloudFlavorCode_desc = item.desc;
    //                         return true;
    //                     }
    //                 });
    //             }
    //             if (data.flavorType == 2) {
    //                 this.configure.wlfwqList.some((item) => {
    //                     if (item.code == data.cloudFlavorCode) {
    //                         data.cloudFlavorCode_label = item.serviceName;
    //                         data.cloudFlavorCode_desc = item.remark;
    //                         return true;
    //                     }
    //                 });
    //             }
    //         });
    //         let aqchecked=[]
    //         detail.safeProducts.forEach(data=>{
    //               aqchecked.push(data.productCode)
    //         })
    //         detail.aqchecked=aqchecked
    //         this.form =JSON.parse(JSON.stringify(detail));
    //         this.oldform =JSON.parse(JSON.stringify(detail));
    //         this.loading = false
    //   })
    // },
    next() {
      let form = JSON.parse(JSON.stringify(this.form));
      if (this.aqchecked) {
      }
      let safeProducts = [],
        text = "",
        hostIds = this.hosts.map((item) => {
          return item.id;
        });
      this.aqchecked.forEach((item, index) => {
        this.yyaqList.forEach((it) => {
          if (it.code == item) {
            let count = parseInt(this.aqcheckedCount[index]);
            if (!count || count > 100) {
              text = "安全产品数量应当为1~100";
            } else {
              safeProducts.push({
                productCode: it.code,
                productName: it.serviceName,
                ysNum: 0,
                num: count,
                hostIds,
              });
            }
          }
        });
      });
      if (text) {
        this.$message({
          message: text,
          type: "error",
        });
        return;
      }
      form.safeProductsList = form.safeProductsList.concat(safeProducts);
      form.oldform = this.oldform;
      form.fileList = this.form.fileList;
      this.$emit("next", form);
    },
    //添加修改表格
    addTable(data) {
      data = JSON.parse(JSON.stringify(data));
      if (!data.addFlag) {
        data.insStatus = "UPDATE";
      }
      console.log(data, "erer");
      if (data.flavorType) {
        this.addHosts(data);
      } else if (data.serverCode) {
        this.addDatabases(data);
      } else {
        this.addStoreProducts(data);
      }
    },
    //添加存储产品列表
    addStoreProducts(data) {
      this.configure[data.productCode == "共享型" ? "ccList" : "fwcpList"].some((it) => {
        if (it.code == data.diskServerCode) {
          data.diskServerCode_label = it.serviceName;
          return true;
        }
      });
      let storeProducts = JSON.parse(JSON.stringify(this.form.storeProducts));
      if (this.addShow == 2) {
        storeProducts[this.index] = data;
      } else {
        data.id = uuidv4();
        storeProducts.push(data);
        this.oldform.storeProducts.push(data);
      }
      this.form.storeProducts = storeProducts;
      this.addShow = false;
    },
    //添加修改数据库列表
    addDatabases(data) {
      console.log(data, "xxxxx", this.configure.sjkList);
      //数据库类型
      this.configure.sjkList.some((it) => {
        if (it.code == data.serverCode) {
          data.serverCode_label = it.serviceName;
          return true;
        }
      });
      let databases = JSON.parse(JSON.stringify(this.form.databases));
      if (this.addShow == 2) {
        databases[this.index] = data;
      } else {
        data.id = uuidv4();
        databases.push(data);
        this.oldform.databases.push(data);
      }
      this.form.databases = databases;
      this.addShow = false;
    },
    //添加修改服务器列表
    addHosts(data) {
      //可用域
      this.configure.available_domain.some((item) => {
        if (item.dictValue == data.availableDomain) {
          data.availableDomain_label = item.dictLabel;
          return true;
        }
      });
      // this.configure.codeList.some((item) => {
      //     if (data.cloudFlavorCode == item.specCode) {
      //         item.details.forEach((it) => {
      //             if (it.serviceCode == "vcpu") {
      //                 data.cpuNumber = it.serviceCount;
      //                 data.cpuServerCode = it.serviceCode;
      //             }
      //             if (it.serviceCode == "memory") {
      //                 data.memorySize = it.serviceCount;
      //                 data.memoryServerCode = it.serviceCode;
      //             }
      //         });
      //         return;
      //     }
      // });
      //数据盘类型
      if (data.disks) {
        data.disks.forEach((item) => {
          this.configure.ccList.some((it) => {
            if (it.code == item.diskServerCode) {
              item.diskServerCode_label = it.serviceName;
              return true;
            }
          });
        });
      }
      if (data.flavorType == 1) {
        //系统盘类型
        if (data.osDisk) {
          this.configure.storage_type.some((item) => {
            if (item.code == data.osDisk.diskServerCode) {
              data.osDisk.diskServerCode_label = item.serviceName;
              return true;
            }
          });
        }
        //规格
        this.configure.codeList.some((item) => {
          if (item.specCode == data.cloudFlavorCode) {
            data.cloudFlavorCode_label = item.specName;
            data.cloudFlavorCode_desc = item.desc;
            return true;
          }
        });
      }
      if (data.flavorType == 2) {
        this.configure.wlfwqList.some((item) => {
          if (item.code == data.cloudFlavorCode) {
            data.cloudFlavorCode_label = item.serviceName;
            data.cloudFlavorCode_desc = item.remark;
            return true;
          }
        });
      }
      let hosts = JSON.parse(JSON.stringify(this.form.hosts));
      if (this.addShow == 2) {
        if (
          data.hostName &&
          data.hostName == data.instanceName //+ "_" + data.num
        ) {
          hosts[this.index] = data;
          this.hosts[Number(this.index) + Number(this.hostsIndex)] = data; //新增公共服务器+历史服务器
        } else {
          hosts.splice(this.index, 1);
          this.hosts.splice(Number(this.index) + Number(this.hostsIndex), 1);
          let sum = 0;
          hosts.forEach((item) => {
            if (item.instanceName == data.instanceName && item.num > sum) {
              sum = item.num;
            }
          });
          ////新增公共服务器+历史服务器
          this.hosts.forEach((item) => {
            if (item.instanceName == data.instanceName && item.num > sum) {
              sum = item.num;
            }
          });
          data.num = sum + 1;
          data.hostName = data.instanceName; //+ "_" + data.num;
          hosts.push(data);
          //新增公共服务器+历史服务器
          this.hosts.push(data);
        }
      } else {
        let num = Number(data.instanceNum);
        data.instanceNum = 1;
        let sum = 0;
        hosts.forEach((item) => {
          if (item.instanceName == data.instanceName && item.num > sum) {
            sum = item.num;
          }
        });
        //新增公共服务器+历史服务器
        this.hosts.forEach((item) => {
          if (item.instanceName == data.instanceName && item.num > sum) {
            sum = item.num;
          }
        });
        for (let i = 0; i < num; i++) {
          let temp = JSON.parse(JSON.stringify(data));
          if (!temp.num) {
            temp.num = sum + i + 1;
          }
          temp.id = uuidv4();
          temp.hostName = temp.instanceName; //+ "_" + temp.num;
          hosts.push(temp);
          this.oldform.hosts.push(temp);
          this.hosts.push(temp);
        }
      }
      this.form.hosts = hosts;
      this.addShow = false;
    },
    //显示弹窗
    showAdd(num, data, index) {
      this.index = index;
      this.addShow = num;
      setTimeout(() => {
        this.$refs.addBdialog.init(num == 2 ? JSON.parse(JSON.stringify(data)) : false);
      }, 200);
    },
    huanyuan(data, index, num) {
      let form = JSON.parse(JSON.stringify(this.form));
      if (num == 1) {
        form.hosts[index] = this.oldform.hosts[index];
      } else if (num == 2) {
        let flag = form.hosts.some((item) => {
          return item.id == data.hostId && item.insStatus != "REMOVE";
        });
        if (flag) {
          form.databases[index] = this.oldform.databases[index];
        } else {
          this.$message({
            type: "error",
            message: "请先还原相关服务器",
          });
        }
      } else if (num == 3) {
        if (!data.hostIds) {
          form.storeProducts[index] = this.oldform.storeProducts[index];
        } else {
          let flag = false;
          flag = form.hosts.some((item) => {
            if (data.hostIds.indexOf(item.id) > -1 && item.insStatus == "REMOVE") {
              return true;
            } else {
              return false;
            }
          });
          if (flag) {
            this.$message({
              type: "error",
              message: "请先还原相关服务器",
            });
          } else {
            form.storeProducts[index] = this.oldform.storeProducts[index];
          }
        }
      } else {
        form.safeProducts[index] = this.oldform.safeProducts[index];
      }
      this.form = form;
    },
    //删除
    del(data, index, num) {
      let form = JSON.parse(JSON.stringify(this.form));
      if (num == 1) {
        form.hosts[index].insStatus = "REMOVE";
        form.databases.forEach((item) => {
          if (item.hostId == data.id) {
            item.insStatus = "REMOVE";
          }
        });
        form.storeProducts.forEach((item) => {
          if (item.hostIds && item.hostIds.indexOf(data.id) > -1) {
            item.insStatus = "REMOVE";
          }
        });
      } else if (num == 2) {
        form.databases[index].insStatus = "REMOVE";
      } else if (num == 3) {
        form.storeProducts[index].insStatus = "REMOVE";
      } else {
        form.safeProducts[index].insStatus = "REMOVE";
      }
      this.form = form;
    },
  },
};
</script>
<style>
.el-form-item--medium .el-form-item__label {
  text-align: left !important;
}
</style>
<style scoped lang="less">
.dialog {
  margin-bottom: 30px;
  font-size: 12px;

  .title {
    text-align: left;
    margin-bottom: 20px;
    font-size: 16px;
    font-weight: bold;
    padding-left: 4px;
    border-left: 4px solid #38b3aa;
  }
  .wrap {
    display: flex;
    background: #faf9ff;
    margin-top: 20px;
    border-radius: 10px;
    .wrap_title {
      padding: 0 10px;
      background: #f4f4f4;
      border-top-left-radius: 10px;
      border-bottom-left-radius: 10px;
      div {
        height: 100%;
        width: 14px;
        font-weight: bold;
        display: flex;
        flex-direction: column;
        justify-content: center;
      }
    }
    .wrap_item {
      display: flex;
      margin-top: 20px;

      div:first-child {
        width: 90px;
        font-weight: bold;
      }
      i {
        line-height: 28px;
        margin-right: 10px;
        font-size: 20px;
        color: #e83112;
      }
    }
  }
  .msg {
    padding: 0 20px 20px 0px;
    background: #faf9ff;
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 30px;
    border-radius: 10px;

    .wra2p {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
    }

    .item {
      margin-left: 20px;
      width: calc(33.33% - 20px);
      min-width: 340px;
      display: flex;
    }
  }
}
</style>
